package com.ee.chat.admin.controller.usermanage;

import com.ee.chat.admin.service.IUserService;
import com.ee.chat.common.bean.Result;
import com.ee.chat.common.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    private Logger log = LoggerFactory.getLogger(UserController.class);

    @Resource
    IUserService userService;

    /**
     * 获取用户信息列表
     * @Author Shane
     * @Date 2019/9/1110:35
     * @param status    用户状态
     * @param host      用户身份
     * @return
     **/
    @RequestMapping("list")
    public Result list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit, String keyword,
                       Integer status, Integer host, Integer gender, Integer identity, String createTime, String field, String sort){
        try {
            return userService.list(request, page, limit, keyword, status, host, gender, identity, createTime, field, sort);
        } catch (Exception e){
            log.error("【获取用户信息列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑用户
     * @Author Shane
     * @Date 2019/9/1118:25
     * @param
     * @return
     **/
    @RequestMapping("toEdit")
    public Result toEdit(HttpServletRequest request, @RequestParam Integer id){
        try {
            return userService.toEdit(request, id);
        } catch (Exception e){
            log.error("【编辑用户错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存用户
     * @Author Shane
     * @Date 2019/9/11 21:56
     * @param
     * @return
     */
    @RequestMapping("edit")
    public Result edit(HttpServletRequest request, User user){
        try {
            return userService.edit(request, user);
        } catch (Exception e){
            log.error("【保存用户错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新用户状态
     * @Author Shane
     * @Date 2019/9/1118:12
     * @param userId    用户id
     * @param type      封禁类型，-1-解除封禁  0-永久封禁  1-时间段封禁
     * @param hour      封禁时间
     * @param reason    理由
     * @return
     **/
    @RequestMapping("updateStatus")
    public Result forbidden(HttpServletRequest request, @RequestParam Integer userId, @RequestParam Integer type,
                            @RequestParam(required = false) Integer hour,  @RequestParam Integer recall,
                            @RequestParam(required = false) String reason){
        try {
            return userService.updateStatus(request, userId, type, hour, recall, reason);
        } catch (Exception e){
            log.error("【更新用户状态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新用户可认证状态
     * @Author Shane
     * @Date 2020/7/8 14:41
     * @param userId    用户id
     * @audit   状态，0-开启  1-关闭
     * @return
     */
    @RequestMapping("updAudit")
    public Result updAudit(HttpServletRequest request, @RequestParam Integer userId, @RequestParam Integer audit){
        try {
            return userService.updAudit(request, userId, audit);
        } catch (Exception e){
            log.error("【更新用户可认证状态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 禁用/启用设备
     * @Author AppiJ
     * @Date 2020/10/21 22:42
     * @param
     * @return
     */
    @RequestMapping("disableImei")
    public Result disableImei(HttpServletRequest request, @RequestParam Integer userId, @RequestParam String imei, String reason){
        try {
            return userService.disableImei(request, userId, imei, reason);
        } catch (Exception e){
            log.error("【禁用/启用设备错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 去编辑邀请者
     * @Author AppiJ
     * @Date 2021/2/4 15:45
     * @param
     * @return
     */
    @RequestMapping("toEditInvite")
    public Result toEditInvite(HttpServletRequest request, @RequestParam Integer userId){
        try {
            return userService.toEditInvite(request, userId);
        } catch (Exception e){
            log.error("【编辑邀请者错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑邀请者
     * @Author Shane
     * @Date 2020/1/27 14:28
     * @param type  邀请类型，0-app邀请  1-渠道邀请
     * @return
     */
    @RequestMapping("editInvite")
    public Result editInvite(HttpServletRequest request, @RequestParam Integer editType, @RequestParam Integer userId, Integer type, Integer inviteId){
        try {
            return userService.editInvite(request, editType, userId, type, inviteId);
        } catch (Exception e){
            log.error("【编辑邀请者错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 钱包充值
     * @Author Shane
     * @Date 2019/9/1118:23
     * @param id    用户id
     * @param type  充值类型，0-金币充值  1-积分充值
     * @param number    充值数量
     * @return
     **/
    @RequestMapping("recharge")
    public Result recharge(HttpServletRequest request, @RequestParam Integer id, @RequestParam Integer type,
                           @RequestParam Double number, @RequestParam String desc){
        try {
            return userService.recharge(request, id, type, number, desc);
        } catch (Exception e){
            log.error("【用户充值错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新性别
     * @Author AppiJ
     * @Date 2020/6/12 12:10
     * @param
     * @return
     */
    @RequestMapping("changeGender")
    public Result changeGender(HttpServletRequest request, @RequestParam Integer id){
        try {
            return userService.changeGender(request, id);
        } catch (Exception e){
            log.error("【更新性别错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑备注
     * @Author AppiJ
     * @Date 2020/6/12 12:28
     * @param
     * @return
     */
    @RequestMapping("editRemark")
    public Result editRemark(HttpServletRequest request, @RequestParam Integer id, String remark){
        try {
            return userService.editRemark(request, id, remark);
        } catch (Exception e){
            log.error("【编辑备注错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新通话权限
     * @Author Shane
     * @Date 2019/12/26 11:15
     * @param
     * @return
     **/
    @RequestMapping("updateCall")
    public Result updateCall(HttpServletRequest request, @RequestParam Integer id, @RequestParam Integer call){
        try {
            return userService.updateCall(request, id, call);
        } catch (Exception e){
            log.error("【更新通话权限错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新IM权限
     * @Author Shane
     * @Date 2020/6/16 18:37
     * @param
     * @return
     */
    @RequestMapping("updateIM")
    public Result updateIM(HttpServletRequest request, @RequestParam Integer id, @RequestParam Integer im){
        try {
            return userService.updateIM(request, id, im);
        } catch (Exception e){
            log.error("【更新IM权限错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 更新用户人头奖状态
     * @Author Shane
     * @Date 2020/7/8 14:41
     * @param userId    用户id
     * @invitePeopleAward   状态，0-开启  1-关闭
     * @return
     */
    @RequestMapping("updateIPA")
    public Result updateIPA(HttpServletRequest request, @RequestParam Integer userId, @RequestParam Integer invitePeopleAward){
        try {
            return userService.updateIPA(request, userId, invitePeopleAward);
        } catch (Exception e){
            log.error("【更新用户人头奖状态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 发送客服消息
     * @Author Shane
     * @Date 2020/8/3 11:41
     * @param
     * @return
     */
    @RequestMapping("sendMsg")
    public Result sendMsg(HttpServletRequest request, @RequestParam Integer userId, @RequestParam String msg){
        try {
            return userService.sendMsg(request, userId, msg);
        } catch (Exception e){
            log.error("【发送客服消息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取用户详细信息
     * @Author AppiJ
     * @Date 2020/12/8 14:39
     * @param
     * @return
     */
    @RequestMapping("toUserInfo")
    public Result toUserInfo(HttpServletRequest request, @RequestParam Integer id){
        try {
            return userService.toUserInfo(request, id);
        } catch (Exception e){
            log.error("【获取用户详细信息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑用户im
     * @param request
     * @param userId
     * @return
     */
    @RequestMapping("toEditImLimit")
    public Result toEditImLimit(HttpServletRequest request, @RequestParam Integer userId){
        try {
            return userService.toEditImLimit(request, userId);
        } catch (Exception e){
            log.error("【编辑用户im错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 保存用户im
     * @param request
     * @param userId
     * @return
     */
    @RequestMapping("editImLimit")
    public Result editImLimit(HttpServletRequest request, Integer userId, String type, Integer num, String time){
        try {
            return userService.editImLimit(request, userId, type, num, time);
        } catch (Exception e){
            log.error("【保存用户im错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 编辑切换支付渠道
     * @param request
     * @param userId
     * @return
     */
    @RequestMapping("toEditPayConfig")
    public Result toEditPayConfig(HttpServletRequest request, Integer userId){
        try {
            return userService.toEditPayConfig(request, userId);
        } catch (Exception e){
            log.error("【编辑切换支付渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 切换支付渠道
     * @param request
     * @param userId
     * @param payWay    支付方式，1-支付宝  2-微信
     * @param type      支付方式，0-原生  1-非原生
     * @return
     */
    @RequestMapping("editPayConfig")
    public Result editPayConfig(HttpServletRequest request, Integer userId, Integer payWay, Integer type){
        try {
            return userService.editPayConfig(request, userId, payWay, type);
        } catch (Exception e){
            log.error("【切换支付渠道错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 设置清退
     * @param request
     * @param userId
     * @param clean 1-申请清退
     * @return
     */
    @RequestMapping("setClean")
    public Result setClean(HttpServletRequest request, Integer userId, Integer clean, String reason){
        try {
            return userService.setClean(request, userId, clean, reason);
        } catch (Exception e){
            log.error("【设置清退错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 提交清退提现申请
     * @param request
     * @param userId
     * @return
     */
    @RequestMapping("submitCleanWithdraw")
    public Result submitCleanWithdraw(HttpServletRequest request, Integer userId, String alipayName, String alipayNo, Double credit, Double amount){
        try {
            return userService.submitCleanWithdraw(request, userId, alipayName, alipayNo, credit, amount);
        } catch (Exception e){
            log.error("【提交清退提现申请错误】", e);
        }
        return Result.returnFailure();
    }
}
